<template>
  <div class="dishes">
    <div class="box clearfix">

      <i class="search_icon" @click="clickSearchBtn" v-show="!searchFlag"></i>

      <div class="search_box" v-show="searchFlag">
        <div class="back-btn" @click="showList">菜单
          <i></i>
        </div>
        <div class="input_box">
          <i class="search_icon_small"></i>
          <input type="text" placeholder="请输入菜名" v-model="searchV" @input="changeSearch">
          <i class="deleted_small" @click="clearInput" v-show="searchV"></i>
        </div>
      </div>

      <ul class="menuMoreLoad clearfix " v-show="!searchFlag">
        <li>
          <div class="loadLogo sbd"></div>
          <div class="name">随便点</div>
        </li>
        <li>
          <div class="loadLogo rxb"></div>
          <div class="name">热销榜</div>
        </li>
        <li>
          <div class="loadLogo dgdc"></div>
          <div class="name">点过的菜</div>
        </li>
      </ul>
      <div class="" v-show="!searchFlag">
        <div class="recommend section" id="tap0" v-show="menu0.recipe&&menu0.recipe.length">
          <div class="d_title">{{ menu0.type_name }}</div>
          <ul>
            <li class="menu-sort-bigModule0" v-for="lis in menu0.recipe" @click="goToDetail(lis.recipe_id)">

              <div class="bigMenuImg0">
                <i class="order_num" v-show="lis.order_num">{{ lis.order_num }}</i>
                <img :src="lis.pic_url" alt="">
                <div :class="lis.d_num=='0'?'soldOut0 outShow':'soldOut0'">
                  <img src="../assets/soldOut.png" alt="">
                </div>
                <div class="tag0" v-if="!!lis.feature_name">{{ lis.feature_name }}</div>
                <div class="infoLayer0">
                  <div class="fl">
                    <div class="menuName0">{{ lis.name }}</div>
                    <div class="menu-hot0"></div>
                  </div>
                  <div class="menuPrice0 fr">￥{{ lis.price/100 }}</div>
                </div>
              </div>


            </li>

          </ul>
        </div>
        <template v-for="(item,index) in menu">
          <div class="recommend section" :id="'tap'+(index+1)" v-show="item.recipe&&item.recipe.length">
            <div class="d_title">{{ item.type_name }}</div>
            <ul class="ul_dist2">
              <li class="menu-sort-bigModule" v-for="lis in item.recipe" @click="goToDetail(lis.recipe_id)">

                <div class="bigMenuImg">
                  <i class="order_num" v-show="lis.order_num">{{ lis.order_num }}</i>
                  <img :src="lis.pic_url" alt="">
                  <div :class="lis.d_num=='0'?'soldOut outShow':'soldOut'">
                    <img src="../assets/soldOut.png" alt="">
                  </div>
                  <div class="tag" v-if="!!lis.feature_name">{{ lis.feature_name }}</div>
                  <div class="infoLayer">
                    <div class="menuName_box">
                      <span class="menuName fl">{{ lis.name }}</span>
                      <div class="menu-hot fl"></div>
                    </div>


                    <div class="menuPrice ">￥{{ lis.price/100 }}</div>
                  </div>
                </div>


              </li>

            </ul>
          </div>
        </template>
      </div>


      <div class="empty" v-show="searchFlag">
        <img src="../assets/hello.png" alt="">
        <div class="word">

          <p class="p2">
            {{ !searchV?'客官，请在输入框中输入菜名':'客官，本店没有这个菜'}}

          </p>
        </div>
      </div>


    </div>

    <div class="nav_detail">
      <ul>
        <li class="dpxx" @click="godpxx">
          <span>店铺信息</span>
        </li>
        <li class="cd" @click="hideNav">
          <span>菜单</span>
        </li>
        <li class="gwc" @click="gogwc">
          <span>购物车</span>
        </li>
        <li class="ydgdc" @click="goydgdc">
          <span>已下单的菜</span>
        </li>
        <li class="jz" @click="gojz">
          <span>结账</span>
        </li>
        <li class="fh" @click="hideNav">
          <span>返回</span>
        </li>
      </ul>
    </div>

    <div class="mask"></div>
    <div class="slide_box" v-show="!searchFlag">
      <div class="slide_btn" @click="showSlideList">
        <p>菜类</p>
      </div>
      <ul class="slider-list" @click="hideSlideList">
        <li class="slider-title">菜类</li>
        <li class="template">随便点
          <span class="icon"></span>
        </li>
        <li class="sales-list">本店销量榜
          <span class="icon"></span>
        </li>
        <li class="mine-list">我点过的菜
          <span class="icon"></span>
        </li>
        <li class="slider-content" v-for="(item,index) in cailei" @click="onTap" :data-tap="'tap'+index">{{ item }}</li>

      </ul>
    </div >

    <div class="bottom_btns">
      <div class="b_btn btn_nav" @click="showNav">
        <i></i>
        导航
      </div>
      <!--<router-link :to="{path: '/dishesList'}" >-->
        <!--<div class="b_btn btn_jxdc">-->
          <!--<i></i>-->
          <!--继续点菜-->
        <!--</div>-->
      <!--</router-link>-->

      <router-link :to="{path: '/shoppingCart'}">
        <div class="b_btn btn_order">
          <i></i>
          购物车
        </div>
      </router-link>

    </div>

    <div class="bg"></div>
  </div>
</template>

<script>
  import bus from '../assets/js/eventBus'
  export default {
    data (){
      return {
        menu: [],
        menu0: {},
        cailei:[],
        isShowSlider: false,
        ll: false,
        searchFlag:false,
        searchV:''
      }
    },
    created (){

      console.log('kkk99');
      this.$http.get(this.kdUrl.url_host+'version=1&resource=menu&method=menu&r_id=1000&token=' + localStorage.getItem("kd_token")).then((res) => {
        console.log(res)
        let menuAll = res.body.data.menu
        /*测试用*/
        let recipe = menuAll[1].recipe
        for(var j=2,lenj=menuAll.length;j<lenj;j++){
          //menuAll[j].recipe = recipe
        }


        this.menu0 = menuAll[0]
        this.menu = menuAll.slice(1)
        for(var i=0,len=menuAll.length;i<len;i++){
          this.cailei.push(menuAll[i].type_name);

        }

      }, (err) => {
        console.log(err);
      })
    },
    mounted (){
      console.log('kkk101010');
      var that = this
      bus.$on('a-send',function (msg) {
        console.log('busmsg')
        console.log(msg)
        let menuAll = msg.menu
        that.menu0 = menuAll[0]
        that.menu = menuAll.slice(1)
        for(var i=0,len=menuAll.length;i<len;i++){
          that.cailei.push(menuAll[i].type_name);
        }
      })



    },
    methods: {
      showSlideList (){
        if (!this.isShowSlider) {
          $('.mask').fadeIn()
          $('.slide_box').animate({right: '0'}, 'fast')
          this.isShowSlider = !this.isShowSlider
        } else {
          $('.mask').fadeOut()
          $('.slide_box').animate({right: '-38%'}, 'fast')
          this.isShowSlider = !this.isShowSlider
        }

      },
      hideSlideList (){
        $('.mask').fadeOut()
        $('.slide_box').animate({right: '-38%'}, 'fast')
        this.isShowSlider = !this.isShowSlider
      },
      onTap (e){
        let tapId = e.target.getAttribute('data-tap')
        console.log(tapId);
        document.getElementById(tapId).scrollIntoView()
      },

      hhh (h){
        console.log(h);
      },
      showNav (){
        $('.mask').fadeIn()
        $('.nav_detail').fadeIn()
      },
      hideNav (){
        $('.mask').fadeOut()
        $('.nav_detail').fadeOut()
      },
      godpxx (){
        this.$router.push('/restaurantInfo')
      },
      gocd (){
        this.$router.push('/dishesList')
      },
      gogwc (){
        this.$router.push('/shoppingCart')
      },
      goydgdc (){
        this.$router.push({path:'/order'})
      },
      gojz (){
        this.$router.push({path:'/order'})
      },
      goToDetail (recipe_id){

        console.log(recipe_id)
        localStorage.setItem("recipe_id",recipe_id);
        this.$router.push('/dishesDetail')
      },
      clearInput (){
        this.searchV = ''
      },
      clickSearchBtn (){
        this.searchFlag = true
        this.searchV = ''
      },
      changeSearch (){
        console.log('kk')
        console.log(this.searchV)
        this.$http.get(this.kdUrl.url_host+'version=1&resource=menu&method=menu_search&token=' + localStorage.getItem("kd_token")+'&name='+this.searchV).then((res) => {
          console.log('search')
          console.log(res)
          if(res.body.data.menu){

          }
       },(err) => {

        })
      },
      showList (){
        this.searchFlag = false
      }
    }


  }
</script>

<style scoped>

  .slide-trans-mask-enter-active {
    transition: all .5s;
  }

  .slide-trans-mask-enter {
    opacity: 1;
    /*transform: translateX(900px);*/
  }

  .slide-trans-box-enter-active {
    transition: all .5s;
  }

  .slide-trans-box-enter {
    right: 0;
    /*transform: translateX(900px);*/
  }

  .dishes {
    color: #fff;
  }

  .box {
    width: 95%;
    margin: 0 auto;
    padding-top: 60px;
    position: relative;
  }
  .search_icon,.search_icon_small{
    position: absolute;
    top: 10px;;
    right: 0;
    width: 30px;
    height: 30px;
    background-image: url('../assets/theme_dark.png');
    background-repeat: no-repeat;
    background-size: 600px 720px;
    background-position:-236px -18px ;
  }
  .search_icon_small{
    width: 18px;
    height: 18px;
    left: 0;
    top: 4px;
    background-size: 360px 432px;
    background-position:-141px -11px ;

  }
  .search_box{
    height: 30px;
    position: absolute;
    top: 15px;;
    width: 100%;
    left: 0;
    padding-left: 70px;
  }
  .back-btn {
    width: 60px;
    position: absolute;
    top: 0;
    left:0;
    height: 30px;
    line-height: 30px;
    font-size: 14px;
    border-radius: 15px;
    padding: 0 10px;
    padding-left: 20px;
    color: #fff;
    margin-right: 15px;
    background: rgba(120,120,120,.6);
  }
  .back-btn i{
    position: absolute;
    border-top: 2px solid #fff;
    border-left:2px solid #fff;
    width: 8px;
    top: 11px;
    left: 8px;
    height: 8px;
    transform: rotate(-45deg);
  }
  .input_box{
    position: relative;
    height: 30px;
    width: 90%;
    padding: 0 25px;
    border-radius: 5px;
    background: rgba(120,120,120,.6);
  }
  .deleted_small{
    position: absolute;
    right: 5px;
    top: 6px;
    width: 18px;
    height: 18px;
    background: #ccc;
    border-radius: 50%;
  }
  .deleted_small:after{
    content: '';
    position: absolute;
    top:3px;
    right: 2px;
    width: 12px;
    height: 12px;
    background-image: url('../assets/deleted_s.png');
    background-size: 12px 12px;
    background-repeat: no-repeat;


  }

  .input_box input{
    height: 30px;
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    color: #fff;
  }

  .empty{
    margin-top: 80px;
    height: 130px;
    padding: 15px 2% 10px 10%;
  }
  .empty img{

    width: 25%;
    vertical-align: middle;
  }
  .word{
    display: inline-block;
    vertical-align: middle;
    padding-left: 10%;
    width: 73%;
  }

  .word .p2{
    width: 85%;
    font-size: 14px;
    color: #999;
  }




  .menuMoreLoad {
    background: rgba(255, 255, 255, .7);
    height: 60px;
    width: 100%;
    margin: 0 auto 20px;
    overflow: hidden;
    border-radius: 5px;
  }

  .menuMoreLoad li {
    padding-top: 5px;
    float: left;
    height: 60px;
    width: 33.3%;
    position: relative;
  }

  .menuMoreLoad li:after {
    content: "";
    display: block;
    width: 1px;
    height: 50%;
    position: absolute;
    right: 0;
    top: 25%;
    background: #fff;
  }

  .menuMoreLoad li:last-of-type:after {
    width: 0px;
  }

  .menuMoreLoad li .sbd {
    background-image: url('../assets/sbd.png');
  }

  .menuMoreLoad li .rxb {
    background-image: url('../assets/rxb.png');
  }

  .menuMoreLoad li .dgdc {
    background-image: url('../assets/dgdc.png');
  }

  .menuMoreLoad li .loadLogo {
    background-size: 22px;
    background-repeat: no-repeat;
    width: 22px;
    height: 22px;
    margin: 0 auto;
  }

  .menuMoreLoad li .name {
    margin-top: 5px;
    text-align: center;
    font-size: 12px;
    color: #333;
  }

  /*主菜单*/
  .section {
    text-align: center;
    margin-bottom: 10px;
  }

  .d_title {
    display: inline-block;
    border: 1px solid #fff;
    font-size: 15px;
    font-weight: 400;
    padding: 0 10px;
    margin: 0 auto 20px;
    position: relative;
  }

  .d_title:before, .d_title:after {
    content: "";
    top: 2px;
    width: 20px;
    -webkit-background-size: contain;
    background-size: contain;
    background-repeat: no-repeat;
    height: 27px;
  }

  .d_title:before {
    position: absolute;
    left: -10px;
    background-image: url('../assets/title_left.png');
  }

  .d_title:after {
    position: absolute;
    right: -20px;
    background-image: url('../assets/title_right.png');
  }

  .menu-sort-bigModule0 {
    height: 230px;
    width: 100%;
    margin-bottom: 15px;
  }

  .bigMenuImg0 {

    height: 100%;
    position: relative;
  }

  .bigMenuImg0 img {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;

  }

  .bigMenuImg0 .tag0 {
    background: #D0021B;
    padding: 5px;
    border-radius: 3px;
    position: absolute;
    top: 5px;
    left: 5px;
  }

  .bigMenuImg0 .infoLayer0 {
    position: absolute;
    bottom: 0;
    height: 60px;
    width: 100%;
    background: #000;
    opacity: 0.7;
    overflow: hidden;
    padding: 0 10px;
  }

  .infoLayer0 .menuName0, .infoLayer0 .menuPrice0 {
    height: 60px;
    line-height: 60px;
    font-size: 18px;
    display: inline-block;
  }

  .infoLayer0 .menu-hot0 {
    display: inline-block;
    background-image: url('../assets/menu_hot.png');
    background-size: contain;
    width: 11px;
    margin-left: 5px;
    height: 18px;
    background-repeat: no-repeat;
    vertical-align: middle;

  }

  .infoLayer0 .menuPrice0 {
    color: #D0021B;
    font-weight: 900;
  }

  /*第二个菜单开始*/
  .ul_dist2 {
    overflow: hidden;
  }

  ul .menu-sort-bigModule {
    width: 32%;
    margin-right: 2%;
    margin-bottom: 15px;
    float: left;
  }

  ul .menu-sort-bigModule:nth-of-type(3n) {
    margin-right: 0;
  }

  .bigMenuImg {
    height: 100%;
    position: relative;
  }
  .order_num{
    position: absolute;
    width: 15px;
    height: 15px;
    top: 1px;;
    right: 1px;
    background: red;
    color: #fff;
    text-align: center;
    line-height: 15px;
    border-radius: 50%;
    z-index: 20;
  }
  .bigMenuImg img {
    height: 80px;
    width: 100%;

  }
  .soldOut,.soldOut0{
    width: 100%;
    height: 80px;
    position: absolute;
    top:0;
    left: 0;
    z-index: 45;
    background: #000;
    opacity: 0.5;
    padding-top: 10px;
    display: none;
  }
  .outShow{
    display: block;
  }

  .soldOut0{
    height: 230px;
  }
  .soldOut img{
    height: 60px;
    width: 60px;
  }
  .soldOut0 img{
    width: 100px;
    height: 100px;
    position: absolute;
    top:45px;
    left: 50%;
    transform: translateX(-50%);
  }

  .bigMenuImg .tag {
    background: #D0021B;
    padding: 2px;
    border-radius: 2px;
    position: absolute;
    top: 3px;
    left: 3px;
  }

  .bigMenuImg .infoLayer {

  }

  .menuName_box {
    overflow: hidden;
  }

  .infoLayer .menuName {
    display: inline-block;

    font-size: 12px;
  }

  .infoLayer .menu-hot {
    background-image: url('../assets/menu_hot.png');
    background-size: contain;
    width: 11px;
    margin-left: 5px;
    height: 18px;
    background-repeat: no-repeat;
    display: inline-block;
    padding-top: 2px;

  }

  .infoLayer .menuPrice {
    text-align: left;
    color: #D0021B;
    font-weight: 900;
  }

  /*右边导航栏*/
  .mask {
    height: 100%;
    width: 100%;
    position: fixed;
    top: 0;
    left: 0;
    background: #000;
    opacity: 0.5;
    z-index: 50;
    display: none;
  }

  .nav_detail{
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 60;
    display: none;
  }
  .nav_detail ul{
    position: absolute;
    left: 2.5%;
    bottom: 20px;
  }
  .nav_detail li{
    width: 60px;
    height: 60px;
    border:2px solid #fff;
    background: #313131;
    margin-bottom: 10px;
    border-radius: 50%;
    position: relative;
  }
  .nav_detail li:last-of-type{
    margin-bottom: 0;
  }
  .nav_detail li:before{
    content: '';
    position: absolute;
    top: 17px;;
    left: 15px;
    width: 30px;
    height: 25px;
    background-image: url('../assets/theme_dark.png');
    background-repeat: no-repeat;
    background-size: 600px 720px;
  }
  .nav_detail li span{
    color: #fff;
    width: 90px;
    position: absolute;
    top: 17px;
    font-size: 14px;
    left: 72px;
    text-align: left;
  }
  .nav_detail li.dpxx:before{
    background-position: -516px -563px;
    top: 14px;;
    left: 16px;
  }
  .nav_detail li.cd:before{
    background-position: -416px -372px;
    top: 15px;;
    left: 12px;
  }
  .nav_detail li.gwc:before{
    background-position: -322px -372px;
    top: 14px;;
    left: 14px;
  }
  .nav_detail li.ydgdc:before{
    background-position: -228px -562px;
    top: 14px;;
    left: 16px;
  }
  .nav_detail li.jz:before{
    background-position: -130px -562px;
    top: 12px;;
    left: 15px;
  }
  .nav_detail li.fh:before{
    background-position: -130px -471px;
  }

  .slide_box {
    width: 38%;
    position: fixed;
    top: 0;
    right: -38%;
    z-index: 50;
    height: 100%;
    color: #000;
    background: rgba(255, 255, 255, .85);
  }

  .slide_box .slide_btn {
    width: 35px;
    height: 50px;
    position: absolute;
    top: 50%;
    transform: translateY(-25px);
    left: -35px;
    background-image: url('../assets/slide_btn.png');
    background-size: cover;
    text-align: center;
  }

  .slide_box .slide_btn p {
    position: relative;
    top: 25px;
  }
  .slider-list{
    overflow: auto;
    height: 100%;
  }
  .slider-list li {
    height: 40px;
    width: 100%;
    padding-left: 15px;
    font-size: 14px;
    font-weight: 400;
    line-height: 40px;
    border-bottom: 1px solid rgba(153, 153, 153, .3);

  }

  .slider-list .mine-list,.slider-list .template,.slider-list .sales-list{
    padding-left: 35px;
    color: #307ad4;
    position: relative;
  }
  .template .icon,.sales-list .icon,.mine-list .icon{
    width: 22px;
    height: 22px;
    background-image: url('../assets/sbd.png');
    background-size: 22px;
    background-repeat: no-repeat;
    position: absolute;
    left: 10px;
    top: 5px;
  }
  .sales-list .icon{
    background-image: url('../assets/rxb.png');
    left: 10px;
    top: 8px;
  }
  .mine-list .icon{
    background-image: url('../assets/dgdc.png');
    left: 10px;
    top: 8px;
  }

  .bottom_btns{
    height: 60px;
    width: 100%;
    position: fixed;
    bottom: 20px;
    left: 0;
    z-index: 48;
  }
  .b_btn{
    position: absolute;
    top:0;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border:2px solid #fff;
    text-align: center;
    padding-top: 28px;
    background: #313131;
    color: #fff;
    font-size: 12px;
  }

  .btn_order{
    background: #ce2101;
    right: 2.5%;

  }
  .btn_jxdc{
    left: 50%;
    transform: translateX(-50%);
  }

  .btn_nav{
    left: 2.5%;
  }
  .btn_jxdc i,.btn_order i,.btn_nav i{
    position: absolute;
    width: 30px;
    height: 25px;
    background-image: url('../assets/theme_dark.png');
    background-repeat: no-repeat;
    background-size: 600px 720px;
  }
  .btn_jxdc i{
    top: 6px;
    left: 13px;
    background-position: -416px -372px;
  }
  .btn_order i{
    top: 4px;
    left: 14px;
    height: 27px;
    background-position: -322px -370px;
  }
  .btn_nav i{
    top: 5px;
    left: 15px;
    background-position: -129px -276px;
  }

  .bg {
    background-image: url('../assets/bg.jpg');
    -webkit-background-size: cover;
    background-size: cover;
    position: fixed;
    z-index: -1;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
  }



</style>
